package com.entiy;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Sentences {
    private final static BlockingQueue<String> sentenceQueue = new LinkedBlockingQueue<>();
    private final StringBuilder buffer = new StringBuilder();
    private static volatile Sentences instance;

    private Sentences() {}

    public static Sentences getInstance() {
        if (instance == null) {
            synchronized (Sentences.class) {
                if (instance == null) {
                    instance = new Sentences();
                }
            }
        }
        return instance;
    }

    // 添加新句子到队列
    public void addSentence(String sentence) {
        sentenceQueue.offer(sentence);
    }

    // 获取并移除队列头部的句子（阻塞式）
    public String takeSentence() throws InterruptedException {
        return sentenceQueue.take();
    }

    // 获取当前队列中的句子数量
    public int getQueueSize() {
        return sentenceQueue.size();
    }

    public BlockingQueue<String> getSentenceQueue() {
        return sentenceQueue;
    }

    public StringBuilder getBuffer() {
        return buffer;
    }

    public void setBuffer(String buffer) {
        this.buffer.append(buffer);
    }
}